(function(vc) {
    vc.extends({
        propTypes: {
            callBackListener: vc.propTypes.string, //父组件名称
            callBackFunction: vc.propTypes.string //父组件监听方法
        },
        data: {
            addHousekeepingFeeConfigInfo: {
                configId: '',
                feeName: '',
                feeTypeCd: '',
                computingFormula: '',
                computingFormulas: [],
                feePrice: '',
                startTime: '',
                endTime: '',
                isDefault: '',
                isDefaults: [],
                housekeepingFeeTypes: []
            }
        },
        _initMethod: function() {
            //$that._listAddHousekeepingFeeTypes();
            vc.initDate('addStartTime', function(_value) {
                $that.addHousekeepingFeeConfigInfo.startTime = _value;
            });
            vc.initDate('addEndTime', function(_value) {
                $that.addHousekeepingFeeConfigInfo.endTime = _value;
            });
            vc.getDict('housekeeping_fee_config', "is_default", function(_data) {
                $that.addHousekeepingFeeConfigInfo.isDefaults = _data;
            });
            vc.getDict('housekeeping_fee_config', "computing_formula", function(_data) {
                $that.addHousekeepingFeeConfigInfo.computingFormulas = _data;
            });
        },
        _initEvent: function() {
            vc.on('addHousekeepingFeeConfig', 'openAddHousekeepingFeeConfigModal', function() {
                $('#addHousekeepingFeeConfigModel').modal('show');
            });
        },
        methods: {
            addHousekeepingFeeConfigValidate() {
                return vc.validate.validate({
                    addHousekeepingFeeConfigInfo: $that.addHousekeepingFeeConfigInfo
                }, {
                    'addHousekeepingFeeConfigInfo.feeName': [{
                            limit: "required",
                            param: "",
                            errInfo: "费用名称不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "128",
                            errInfo: "费用名称太长"
                        }
                    ],
                    'addHousekeepingFeeConfigInfo.feeTypeCd': [{
                        limit: "maxLength",
                        param: "30",
                        errInfo: "费用类型太长"
                    }],
                    'addHousekeepingFeeConfigInfo.computingFormula': [{
                        limit: "required",
                        param: "",
                        errInfo: "计算公式不能为空"
                    }],
                    'addHousekeepingFeeConfigInfo.startTime': [{
                            limit: "required",
                            param: "",
                            errInfo: "开始时间不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "不是有效的时间格式"
                        }
                    ],
                    'addHousekeepingFeeConfigInfo.endTime': [{
                            limit: "required",
                            param: "",
                            errInfo: "结束时间不能为空"
                        },
                        {
                            limit: "date",
                            param: "",
                            errInfo: "不是有效的时间格式"
                        }
                    ],
                    'addHousekeepingFeeConfigInfo.isDefault': [{
                        limit: "required",
                        param: "",
                        errInfo: "是否未默认费用不能为空"
                    }]
                });
            },
            saveHousekeepingFeeConfigInfo: function() {
                if (!$that.addHousekeepingFeeConfigValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                if ($that.addHousekeepingFeeConfigInfo.computingFormula == '2002' && $that.addHousekeepingFeeConfigInfo.feePrice == "") {
                    vc.toast("请填写单价");
                    return;
                }
                if ($that.addHousekeepingFeeConfigInfo.computingFormula == '3003') {
                    $that.addHousekeepingFeeConfigInfo.feePrice = "0"
                }
                $that.addHousekeepingFeeConfigInfo.shopId = vc.getCurrentCommunity().shopId;
                //不提交数据将数据 回调给侦听处理
                if (vc.notNull($props.callBackListener)) {
                    vc.emit($props.callBackListener, $props.callBackFunction, $that.addHousekeepingFeeConfigInfo);
                    $('#addHousekeepingFeeConfigModel').modal('hide');
                    return;
                }
                vc.http.apiPost(
                    '/housekeepingFeeConfig/saveHousekeepingFeeConfig',
                    JSON.stringify($that.addHousekeepingFeeConfigInfo), {
                        emulateJSON: true
                    },
                    function(json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addHousekeepingFeeConfigModel').modal('hide');
                            $that.clearAddHousekeepingFeeConfigInfo();
                            vc.emit('housekeepingFeeConfigManage', 'listHousekeepingFeeConfig', {});
                            vc.toast("添加成功");
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            //查询方法
            _listAddHousekeepingFeeTypes: function(_page, _rows) {
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        shopId: vc.getCurrentCommunity().shopId
                    }
                };
                //发送get请求
                vc.http.apiGet('/housekeepingFeeType/queryHousekeepingFeeType',
                    param,
                    function(json, res) {
                        var _housekeepingFeeTypeManageInfo = JSON.parse(json);
                        $that.addHousekeepingFeeConfigInfo.housekeepingFeeTypes = _housekeepingFeeTypeManageInfo.data;
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            clearAddHousekeepingFeeConfigInfo: function() {
                $that.addHousekeepingFeeConfigInfo = {
                    configId: '',
                    feeName: '',
                    feeTypeCd: '',
                    computingFormula: '',
                    computingFormulas: [],
                    feePrice: '',
                    startTime: '',
                    endTime: '',
                    isDefault: '',
                    isDefaults: [],
                    housekeepingFeeTypes: []
                };
            }
        }
    });
})(window.vc);